package com.lucher.mes.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lucher.mes.common.Tools;
import com.lucher.mes.dao.RollcallinfoMapper;
import com.lucher.mes.po.Rollcallinfo;
import com.lucher.mes.po.Worklinesectionmachine;

@Controller
@RequestMapping("/rollcallinfo")  
public class RollcallinfoController extends BaseController{
	@Autowired
	private RollcallinfoMapper rollcallinfoDao;
	
	/**
	 * 查询信息
	 */
	@RequestMapping(value = "/findByList")
	public String findByList(Rollcallinfo form) {
		return "rollcallinfo/findRollcallinfoList";
	}
	
	/**
	 * 查询信息Json
	 */
	@ResponseBody
	@RequestMapping(value = "/findListJson")
	public Map<String, Object> findListJson(Rollcallinfo form) {
		//封装JSon的Map
		Map<String, Object> result = new HashMap<String, Object>(); 
		result.put("code", "0");
		List<HashMap<String, Object>> objectlist = new ArrayList<HashMap<String, Object>>();
		
		Integer total = rollcallinfoDao.findByCount(form);
		List<Rollcallinfo> list = rollcallinfoDao.findByListForPage(form);
		
		for (Rollcallinfo rollcallinfo : list) {
			HashMap<String, Object> objectMap = new HashMap<String, Object>();
			
			objectMap.put("id", rollcallinfo.getId());
			objectMap.put("uuid", rollcallinfo.getUuid());
			objectMap.put("prisonercode", rollcallinfo.getPrisonercode());
			objectMap.put("prisonername", rollcallinfo.getPrisonername());
			objectMap.put("status", rollcallinfo.getStatus());
			objectMap.put("machinecode", rollcallinfo.getMachinecode());
			objectMap.put("addtime", StringUtils.isEmpty(rollcallinfo.getAddtime())?"":Tools.getStr(rollcallinfo.getAddtime()).substring(0, 19));
			objectMap.put("reason", rollcallinfo.getReason());
			objectMap.put("remark", rollcallinfo.getRemark());
			
			objectlist.add(objectMap);
		}
		
		result.put("count", total);
		result.put("data", objectlist);
		return result;
	}
	
	/**
	 * 修改未签到原因
	 * @return
	 */
	@ResponseBody //此标志就是返回jesion数据给页面的标志
	@RequestMapping(value="/updateRollcallinfo")
	public Map<String,Object> updateRollcallinfo(Rollcallinfo record) {
		//封装返回给页面的json对象
		HashMap<String,Object> responseJson = new HashMap<String,Object>();
		responseJson.put("code", "0");
		
		//修改关联的工位机
		if(record.getAddtime() == ""){
			record.setAddtime(null);
		}
		rollcallinfoDao.updateByPrimaryKeySelective(record);
		
		responseJson.put("flag", "1");//删除成功
		responseJson.put("msg", "操作成功");
		
		return responseJson;
	}

}
